import { Icon, Menu, Dropdown } from 'antd';
import isEqual from 'lodash/isEqual';

class DraftItemLink extends React.Component {

	constructor(props){
		super(props);
		this.state={
			wfId:-1
		};
	}

	shouldComponentUpdate(nextProps,nextState) {
		const wfbean = this.props.wfbean;
		const wfbeanNext = nextProps.wfbean;
        return !isEqual(wfbean, wfbeanNext) ;
    }

    render() {
		const { wfbean, groups } = this.props;
		const { beagenters, belongtoUsers, wfColl, isImportWf, id, name } = wfbean;

		const menu = (
			<Menu onClick={this.handleMenuClick}>
				{groups.map((group) => {
					return <Menu.Item key={group.id}>{group.name}</Menu.Item>;
				})}

			</Menu>
		);
		return (
			<div className="centerItem" key={id}  >
				<div className="fontItem" >
					<a onClick={this.onNewRequest.bind(this,id,'',0,0)} target="_blank" title={name}>{name}</a>
				</div>
				{
					groups.length<=0?null:<div className= "imageItem" style={{"display":"none"}}>
						<Dropdown overlay={menu} trigger={['click']} onClick={this.handleDropdownClick.bind(this,id)}>
							<Icon type="edit" title={"调整分组"}/>
						</Dropdown>
					</div>
				}
				
			</div>
		);
           	
    };
	//新建流程
	onNewRequest(wfid,f_weaver_belongto_userid,beagenter,isagent,e){
		//计数
		jQuery.post('/workflow/request/AddWorkflowUseCount.jsp',{wfid:wfid});
		let paramstr = `workflowid=${wfid}&isagent=${isagent}&beagenter=${beagenter}&f_weaver_belongto_userid=${f_weaver_belongto_userid}&f_weaver_belongto_usertype=0`;
		this.openFullWindowHaveBar('/workflow/request/CreateRequestForward.jsp?'+paramstr);
	}

	openFullWindowHaveBar(url){
		var redirectUrl = url;
		var width = screen.availWidth - 10;
		var height = screen.availHeight - 50;
		var szFeatures = "top=0,";
		szFeatures += "left=0,";
		szFeatures += "width=" + width + ",";
		szFeatures += "height=" + height + ",";
		szFeatures += "directories=no,";
		szFeatures += "status=yes,toolbar=no,location=no,";
		szFeatures += "menubar=no,";
		szFeatures += "scrollbars=yes,";
		szFeatures += "resizable=yes"; //channelmode
		window.open(redirectUrl, "", szFeatures);
	}

	handleMenuClick = (e) => {
		const { actions } = this.props;
		const { wfId } = this.state;
		actions.changeGroup(e.key, wfId);
	}

	handleDropdownClick = (wfId) => {
		this.setState({ wfId, wfId });
	}
}

export default DraftItemLink;